{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* summary: 第五章实验的代码\n",
    "* author: Mr. GAO\n",
    "* date：2022-9-18\n",
    "\n",
    "* 数据说明：\n",
    "    * 解释变量：\n",
    "        * ['酒精', '苹果酸', '灰', '灰的碱性', '镁', '总酚', '类黄酮', '非黄烷类酚类', '花青素', '颜色强度', '色调', '稀释葡萄酒', '脯氨酸']\n",
    "        * ['alcohol', 'malic_acid', 'ash', 'alcalinity_of_ash', 'magnesium', 'total_phenols', 'flavanoids', 'nonflavanoid_phenols', 'proanthocyanins', 'color_intensity', 'hue', 'od280/od315_of_diluted_wines', 'proline']\n",
    "    * 响应变量：红酒种类，包括['琴酒', '雪莉', '贝尔摩德']['class_0' 'class_1' 'class_2']\n",
    "**********"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 从sklearn.datasets导入红酒数据源"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 导入数据源"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ".. _wine_dataset:\n",
      "\n",
      "Wine recognition dataset\n",
      "------------------------\n",
      "\n",
      "**Data Set Characteristics:**\n",
      "\n",
      "    :Number of Instances: 178\n",
      "    :Number of Attributes: 13 numeric, predictive attributes and the class\n",
      "    :Attribute Information:\n",
      " \t\t- Alcohol\n",
      " \t\t- Malic acid\n",
      " \t\t- Ash\n",
      "\t\t- Alcalinity of ash  \n",
      " \t\t- Magnesium\n",
      "\t\t- Total phenols\n",
      " \t\t- Flavanoids\n",
      " \t\t- Nonflavanoid phenols\n",
      " \t\t- Proanthocyanins\n",
      "\t\t- Color intensity\n",
      " \t\t- Hue\n",
      " \t\t- OD280/OD315 of diluted wines\n",
      " \t\t- Proline\n",
      "\n",
      "    - class:\n",
      "            - class_0\n",
      "            - class_1\n",
      "            - class_2\n",
      "\t\t\n",
      "    :Summary Statistics:\n",
      "    \n",
      "    ============================= ==== ===== ======= =====\n",
      "                                   Min   Max   Mean     SD\n",
      "    ============================= ==== ===== ======= =====\n",
      "    Alcohol:                      11.0  14.8    13.0   0.8\n",
      "    Malic Acid:                   0.74  5.80    2.34  1.12\n",
      "    Ash:                          1.36  3.23    2.36  0.27\n",
      "    Alcalinity of Ash:            10.6  30.0    19.5   3.3\n",
      "    Magnesium:                    70.0 162.0    99.7  14.3\n",
      "    Total Phenols:                0.98  3.88    2.29  0.63\n",
      "    Flavanoids:                   0.34  5.08    2.03  1.00\n",
      "    Nonflavanoid Phenols:         0.13  0.66    0.36  0.12\n",
      "    Proanthocyanins:              0.41  3.58    1.59  0.57\n",
      "    Colour Intensity:              1.3  13.0     5.1   2.3\n",
      "    Hue:                          0.48  1.71    0.96  0.23\n",
      "    OD280/OD315 of diluted wines: 1.27  4.00    2.61  0.71\n",
      "    Proline:                       278  1680     746   315\n",
      "    ============================= ==== ===== ======= =====\n",
      "\n",
      "    :Missing Attribute Values: None\n",
      "    :Class Distribution: class_0 (59), class_1 (71), class_2 (48)\n",
      "    :Creator: R.A. Fisher\n",
      "    :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\n",
      "    :Date: July, 1988\n",
      "\n",
      "This is a copy of UCI ML Wine recognition datasets.\n",
      "https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data\n",
      "\n",
      "The data is the results of a chemical analysis of wines grown in the same\n",
      "region in Italy by three different cultivators. There are thirteen different\n",
      "measurements taken for different constituents found in the three types of\n",
      "wine.\n",
      "\n",
      "Original Owners: \n",
      "\n",
      "Forina, M. et al, PARVUS - \n",
      "An Extendible Package for Data Exploration, Classification and Correlation. \n",
      "Institute of Pharmaceutical and Food Analysis and Technologies,\n",
      "Via Brigata Salerno, 16147 Genoa, Italy.\n",
      "\n",
      "Citation:\n",
      "\n",
      "Lichman, M. (2013). UCI Machine Learning Repository\n",
      "[https://archive.ics.uci.edu/ml]. Irvine, CA: University of California,\n",
      "School of Information and Computer Science. \n",
      "\n",
      ".. topic:: References\n",
      "\n",
      "  (1) S. Aeberhard, D. Coomans and O. de Vel, \n",
      "  Comparison of Classifiers in High Dimensional Settings, \n",
      "  Tech. Rep. no. 92-02, (1992), Dept. of Computer Science and Dept. of  \n",
      "  Mathematics and Statistics, James Cook University of North Queensland. \n",
      "  (Also submitted to Technometrics). \n",
      "\n",
      "  The data was used with many others for comparing various \n",
      "  classifiers. The classes are separable, though only RDA \n",
      "  has achieved 100% correct classification. \n",
      "  (RDA : 100%, QDA 99.4%, LDA 98.9%, 1NN 96.1% (z-transformed data)) \n",
      "  (All results using the leave-one-out technique) \n",
      "\n",
      "  (2) S. Aeberhard, D. Coomans and O. de Vel, \n",
      "  \"THE CLASSIFICATION PERFORMANCE OF RDA\" \n",
      "  Tech. Rep. no. 92-01, (1992), Dept. of Computer Science and Dept. of \n",
      "  Mathematics and Statistics, James Cook University of North Queensland. \n",
      "  (Also submitted to Journal of Chemometrics).\n",
      "\n",
      "['alcohol', 'malic_acid', 'ash', 'alcalinity_of_ash', 'magnesium', 'total_phenols', 'flavanoids', 'nonflavanoid_phenols', 'proanthocyanins', 'color_intensity', 'hue', 'od280/od315_of_diluted_wines', 'proline']\n"
     ]
    }
   ],
   "source": [
    "from sklearn.datasets import load_wine\n",
    "\n",
    "wine_raw = load_wine()\n",
    "print(wine_raw.DESCR)     # 打印红酒数据集的描述\n",
    "print(wine_raw.feature_names)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 将bunch格式的红酒数据转入dataframe格式对象中"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(178, 14)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>alcohol</th>\n",
       "      <th>malic_acid</th>\n",
       "      <th>ash</th>\n",
       "      <th>alcalinity_of_ash</th>\n",
       "      <th>magnesium</th>\n",
       "      <th>total_phenols</th>\n",
       "      <th>flavanoids</th>\n",
       "      <th>nonflavanoid_phenols</th>\n",
       "      <th>proanthocyanins</th>\n",
       "      <th>color_intensity</th>\n",
       "      <th>hue</th>\n",
       "      <th>od280/od315_of_diluted_wines</th>\n",
       "      <th>proline</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>14.23</td>\n",
       "      <td>1.71</td>\n",
       "      <td>2.43</td>\n",
       "      <td>15.6</td>\n",
       "      <td>127.0</td>\n",
       "      <td>2.80</td>\n",
       "      <td>3.06</td>\n",
       "      <td>0.28</td>\n",
       "      <td>2.29</td>\n",
       "      <td>5.64</td>\n",
       "      <td>1.04</td>\n",
       "      <td>3.92</td>\n",
       "      <td>1065.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>13.20</td>\n",
       "      <td>1.78</td>\n",
       "      <td>2.14</td>\n",
       "      <td>11.2</td>\n",
       "      <td>100.0</td>\n",
       "      <td>2.65</td>\n",
       "      <td>2.76</td>\n",
       "      <td>0.26</td>\n",
       "      <td>1.28</td>\n",
       "      <td>4.38</td>\n",
       "      <td>1.05</td>\n",
       "      <td>3.40</td>\n",
       "      <td>1050.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>13.16</td>\n",
       "      <td>2.36</td>\n",
       "      <td>2.67</td>\n",
       "      <td>18.6</td>\n",
       "      <td>101.0</td>\n",
       "      <td>2.80</td>\n",
       "      <td>3.24</td>\n",
       "      <td>0.30</td>\n",
       "      <td>2.81</td>\n",
       "      <td>5.68</td>\n",
       "      <td>1.03</td>\n",
       "      <td>3.17</td>\n",
       "      <td>1185.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>14.37</td>\n",
       "      <td>1.95</td>\n",
       "      <td>2.50</td>\n",
       "      <td>16.8</td>\n",
       "      <td>113.0</td>\n",
       "      <td>3.85</td>\n",
       "      <td>3.49</td>\n",
       "      <td>0.24</td>\n",
       "      <td>2.18</td>\n",
       "      <td>7.80</td>\n",
       "      <td>0.86</td>\n",
       "      <td>3.45</td>\n",
       "      <td>1480.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>13.24</td>\n",
       "      <td>2.59</td>\n",
       "      <td>2.87</td>\n",
       "      <td>21.0</td>\n",
       "      <td>118.0</td>\n",
       "      <td>2.80</td>\n",
       "      <td>2.69</td>\n",
       "      <td>0.39</td>\n",
       "      <td>1.82</td>\n",
       "      <td>4.32</td>\n",
       "      <td>1.04</td>\n",
       "      <td>2.93</td>\n",
       "      <td>735.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   alcohol  malic_acid   ash  alcalinity_of_ash  magnesium  total_phenols  \\\n",
       "0    14.23        1.71  2.43               15.6      127.0           2.80   \n",
       "1    13.20        1.78  2.14               11.2      100.0           2.65   \n",
       "2    13.16        2.36  2.67               18.6      101.0           2.80   \n",
       "3    14.37        1.95  2.50               16.8      113.0           3.85   \n",
       "4    13.24        2.59  2.87               21.0      118.0           2.80   \n",
       "\n",
       "   flavanoids  nonflavanoid_phenols  proanthocyanins  color_intensity   hue  \\\n",
       "0        3.06                  0.28             2.29             5.64  1.04   \n",
       "1        2.76                  0.26             1.28             4.38  1.05   \n",
       "2        3.24                  0.30             2.81             5.68  1.03   \n",
       "3        3.49                  0.24             2.18             7.80  0.86   \n",
       "4        2.69                  0.39             1.82             4.32  1.04   \n",
       "\n",
       "   od280/od315_of_diluted_wines  proline  target  \n",
       "0                          3.92   1065.0       0  \n",
       "1                          3.40   1050.0       0  \n",
       "2                          3.17   1185.0       0  \n",
       "3                          3.45   1480.0       0  \n",
       "4                          2.93    735.0       0  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import copy\n",
    "\n",
    "# 存入dataframe\n",
    "wine_dataframe = pd.concat([pd.DataFrame(wine_raw.data),pd.DataFrame(wine_raw.target)],\n",
    "                            axis=1)\n",
    "wine_dataframe_colomns = copy.copy(wine_raw.feature_names)      # 使用深层拷贝\n",
    "wine_dataframe_colomns.append('target')\n",
    "wine_dataframe.columns = wine_dataframe_colomns\n",
    "\n",
    "print(wine_dataframe.shape)\n",
    "wine_dataframe.head()  # 输出dataframe的前五行"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 构建决策树"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 构建训练集、测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "全部数据集大小：(178, 13)\n",
      "训练集数据大小：(142, 13)\n",
      "测试集数据大小：(36, 13)\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(wine_raw.data, wine_raw.target, test_size=0.2)\n",
    "print(\"全部数据集大小：\" + str(wine_raw.data.shape))\n",
    "print(\"训练集数据大小：\" + str(X_train.shape))\n",
    "print(\"测试集数据大小：\" + str(X_test.shape))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 定义决策树、训练决策树"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.8611111111111112\n"
     ]
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "\n",
    "my_clf_tree = DecisionTreeClassifier()          # 实例化决策树分类器对象\n",
    "my_clf_tree.fit(X_train, y_train)\n",
    "my_clf_score = my_clf_tree.score(X_test, y_test)\n",
    "print(my_clf_score)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 使用训练集给训练好的决策树评分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.8611111111111112\n"
     ]
    }
   ],
   "source": [
    "my_clf_score = my_clf_tree.score(X_test, y_test)\n",
    "print(my_clf_score)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 决策树可视化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 导入graphviz、sklearn的tree包，"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 6.0.1 (20220911.1526)\n -->\n<!-- Title: Tree Pages: 1 -->\n<svg width=\"1114pt\" height=\"552pt\"\n viewBox=\"0.00 0.00 1114.00 552.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 548)\">\n<title>Tree</title>\n<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-548 1110,-548 1110,4 -4,4\"/>\n<!-- 0 -->\n<g id=\"node1\" class=\"node\">\n<title>0</title>\n<path fill=\"#f6fefa\" stroke=\"black\" d=\"M583,-544C583,-544 470,-544 470,-544 464,-544 458,-538 458,-532 458,-532 458,-473 458,-473 458,-467 464,-461 470,-461 470,-461 583,-461 583,-461 589,-461 595,-467 595,-473 595,-473 595,-532 595,-532 595,-538 589,-544 583,-544\"/>\n<text text-anchor=\"middle\" x=\"526.5\" y=\"-528.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">脯氨酸 &lt;= 755.0</text>\n<text text-anchor=\"middle\" x=\"526.5\" y=\"-513.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.66</text>\n<text text-anchor=\"middle\" x=\"526.5\" y=\"-498.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 142</text>\n<text text-anchor=\"middle\" x=\"526.5\" y=\"-483.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [50, 54, 38]</text>\n<text text-anchor=\"middle\" x=\"526.5\" y=\"-468.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 雪莉</text>\n</g>\n<!-- 1 -->\n<g id=\"node2\" class=\"node\">\n<title>1</title>\n<path fill=\"#c1f7d7\" stroke=\"black\" d=\"M499.5,-425C499.5,-425 281.5,-425 281.5,-425 275.5,-425 269.5,-419 269.5,-413 269.5,-413 269.5,-354 269.5,-354 269.5,-348 275.5,-342 281.5,-342 281.5,-342 499.5,-342 499.5,-342 505.5,-342 511.5,-348 511.5,-354 511.5,-354 511.5,-413 511.5,-413 511.5,-419 505.5,-425 499.5,-425\"/>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">od280/od315稀释葡萄酒 &lt;= 2.19</text>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.494</text>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 85</text>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [1, 50, 34]</text>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-349.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 雪莉</text>\n</g>\n<!-- 0&#45;&gt;1 -->\n<g id=\"edge1\" class=\"edge\">\n<title>0&#45;&gt;1</title>\n<path fill=\"none\" stroke=\"black\" d=\"M479.32,-460.91C468.34,-451.47 456.57,-441.34 445.31,-431.65\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"447.46,-428.89 437.6,-425.02 442.9,-434.2 447.46,-428.89\"/>\n<text text-anchor=\"middle\" x=\"439.47\" y=\"-446.25\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">True</text>\n</g>\n<!-- 12 -->\n<g id=\"node13\" class=\"node\">\n<title>12</title>\n<path fill=\"#e99457\" stroke=\"black\" d=\"M739,-425C739,-425 642,-425 642,-425 636,-425 630,-419 630,-413 630,-413 630,-354 630,-354 630,-348 636,-342 642,-342 642,-342 739,-342 739,-342 745,-342 751,-348 751,-354 751,-354 751,-413 751,-413 751,-419 745,-425 739,-425\"/>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">类黄酮 &lt;= 2.3</text>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.251</text>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 57</text>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [49, 4, 4]</text>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-349.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 琴酒</text>\n</g>\n<!-- 0&#45;&gt;12 -->\n<g id=\"edge12\" class=\"edge\">\n<title>0&#45;&gt;12</title>\n<path fill=\"none\" stroke=\"black\" d=\"M583.4,-460.91C596.88,-451.29 611.37,-440.95 625.19,-431.09\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"627.59,-433.68 633.7,-425.02 623.53,-427.98 627.59,-433.68\"/>\n<text text-anchor=\"middle\" x=\"629.58\" y=\"-445.98\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">False</text>\n</g>\n<!-- 2 -->\n<g id=\"node3\" class=\"node\">\n<title>2</title>\n<path fill=\"#975cea\" stroke=\"black\" d=\"M259.5,-306C259.5,-306 137.5,-306 137.5,-306 131.5,-306 125.5,-300 125.5,-294 125.5,-294 125.5,-235 125.5,-235 125.5,-229 131.5,-223 137.5,-223 137.5,-223 259.5,-223 259.5,-223 265.5,-223 271.5,-229 271.5,-235 271.5,-235 271.5,-294 271.5,-294 271.5,-300 265.5,-306 259.5,-306\"/>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">灰的碱性 &lt;= 17.25</text>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.255</text>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 40</text>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 6, 34]</text>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-230.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 贝尔摩德</text>\n</g>\n<!-- 1&#45;&gt;2 -->\n<g id=\"edge2\" class=\"edge\">\n<title>1&#45;&gt;2</title>\n<path fill=\"none\" stroke=\"black\" d=\"M323.89,-341.91C307.65,-332.02 290.18,-321.37 273.58,-311.25\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"275.36,-308.24 265,-306.02 271.71,-314.21 275.36,-308.24\"/>\n</g>\n<!-- 7 -->\n<g id=\"node8\" class=\"node\">\n<title>7</title>\n<path fill=\"#3de684\" stroke=\"black\" d=\"M443,-306C443,-306 338,-306 338,-306 332,-306 326,-300 326,-294 326,-294 326,-235 326,-235 326,-229 332,-223 338,-223 338,-223 443,-223 443,-223 449,-223 455,-229 455,-235 455,-235 455,-294 455,-294 455,-300 449,-306 443,-306\"/>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">脯氨酸 &lt;= 726.5</text>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.043</text>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 45</text>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [1, 44, 0]</text>\n<text text-anchor=\"middle\" x=\"390.5\" y=\"-230.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 雪莉</text>\n</g>\n<!-- 1&#45;&gt;7 -->\n<g id=\"edge7\" class=\"edge\">\n<title>1&#45;&gt;7</title>\n<path fill=\"none\" stroke=\"black\" d=\"M390.5,-341.91C390.5,-333.65 390.5,-324.86 390.5,-316.3\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"394,-316.02 390.5,-306.02 387,-316.02 394,-316.02\"/>\n</g>\n<!-- 3 -->\n<g id=\"node4\" class=\"node\">\n<title>3</title>\n<path fill=\"#39e581\" stroke=\"black\" d=\"M101,-179.5C101,-179.5 12,-179.5 12,-179.5 6,-179.5 0,-173.5 0,-167.5 0,-167.5 0,-123.5 0,-123.5 0,-117.5 6,-111.5 12,-111.5 12,-111.5 101,-111.5 101,-111.5 107,-111.5 113,-117.5 113,-123.5 113,-123.5 113,-167.5 113,-167.5 113,-173.5 107,-179.5 101,-179.5\"/>\n<text text-anchor=\"middle\" x=\"56.5\" y=\"-164.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"56.5\" y=\"-149.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 5</text>\n<text text-anchor=\"middle\" x=\"56.5\" y=\"-134.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 5, 0]</text>\n<text text-anchor=\"middle\" x=\"56.5\" y=\"-119.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 雪莉</text>\n</g>\n<!-- 2&#45;&gt;3 -->\n<g id=\"edge3\" class=\"edge\">\n<title>2&#45;&gt;3</title>\n<path fill=\"none\" stroke=\"black\" d=\"M149.23,-222.91C134.77,-210.99 118.97,-197.98 104.59,-186.12\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"106.7,-183.32 96.75,-179.67 102.25,-188.73 106.7,-183.32\"/>\n</g>\n<!-- 4 -->\n<g id=\"node5\" class=\"node\">\n<title>4</title>\n<path fill=\"#853fe6\" stroke=\"black\" d=\"M253.5,-187C253.5,-187 143.5,-187 143.5,-187 137.5,-187 131.5,-181 131.5,-175 131.5,-175 131.5,-116 131.5,-116 131.5,-110 137.5,-104 143.5,-104 143.5,-104 253.5,-104 253.5,-104 259.5,-104 265.5,-110 265.5,-116 265.5,-116 265.5,-175 265.5,-175 265.5,-181 259.5,-187 253.5,-187\"/>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">类黄酮 &lt;= 1.58</text>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.056</text>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 35</text>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 1, 34]</text>\n<text text-anchor=\"middle\" x=\"198.5\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 贝尔摩德</text>\n</g>\n<!-- 2&#45;&gt;4 -->\n<g id=\"edge4\" class=\"edge\">\n<title>2&#45;&gt;4</title>\n<path fill=\"none\" stroke=\"black\" d=\"M198.5,-222.91C198.5,-214.65 198.5,-205.86 198.5,-197.3\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"202,-197.02 198.5,-187.02 195,-197.02 202,-197.02\"/>\n</g>\n<!-- 5 -->\n<g id=\"node6\" class=\"node\">\n<title>5</title>\n<path fill=\"#8139e5\" stroke=\"black\" d=\"M192.5,-68C192.5,-68 82.5,-68 82.5,-68 76.5,-68 70.5,-62 70.5,-56 70.5,-56 70.5,-12 70.5,-12 70.5,-6 76.5,0 82.5,0 82.5,0 192.5,0 192.5,0 198.5,0 204.5,-6 204.5,-12 204.5,-12 204.5,-56 204.5,-56 204.5,-62 198.5,-68 192.5,-68\"/>\n<text text-anchor=\"middle\" x=\"137.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"137.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 34</text>\n<text text-anchor=\"middle\" x=\"137.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 0, 34]</text>\n<text text-anchor=\"middle\" x=\"137.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 贝尔摩德</text>\n</g>\n<!-- 4&#45;&gt;5 -->\n<g id=\"edge5\" class=\"edge\">\n<title>4&#45;&gt;5</title>\n<path fill=\"none\" stroke=\"black\" d=\"M175.79,-103.73C170.96,-95.06 165.85,-85.9 161,-77.18\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"163.97,-75.33 156.05,-68.3 157.86,-78.74 163.97,-75.33\"/>\n</g>\n<!-- 6 -->\n<g id=\"node7\" class=\"node\">\n<title>6</title>\n<path fill=\"#39e581\" stroke=\"black\" d=\"M324,-68C324,-68 235,-68 235,-68 229,-68 223,-62 223,-56 223,-56 223,-12 223,-12 223,-6 229,0 235,0 235,0 324,0 324,0 330,0 336,-6 336,-12 336,-12 336,-56 336,-56 336,-62 330,-68 324,-68\"/>\n<text text-anchor=\"middle\" x=\"279.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"279.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 1</text>\n<text text-anchor=\"middle\" x=\"279.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 1, 0]</text>\n<text text-anchor=\"middle\" x=\"279.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 雪莉</text>\n</g>\n<!-- 4&#45;&gt;6 -->\n<g id=\"edge6\" class=\"edge\">\n<title>4&#45;&gt;6</title>\n<path fill=\"none\" stroke=\"black\" d=\"M228.66,-103.73C235.27,-94.79 242.28,-85.32 248.91,-76.36\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"251.73,-78.42 254.87,-68.3 246.11,-74.26 251.73,-78.42\"/>\n</g>\n<!-- 8 -->\n<g id=\"node9\" class=\"node\">\n<title>8</title>\n<path fill=\"#39e581\" stroke=\"black\" d=\"M393,-179.5C393,-179.5 296,-179.5 296,-179.5 290,-179.5 284,-173.5 284,-167.5 284,-167.5 284,-123.5 284,-123.5 284,-117.5 290,-111.5 296,-111.5 296,-111.5 393,-111.5 393,-111.5 399,-111.5 405,-117.5 405,-123.5 405,-123.5 405,-167.5 405,-167.5 405,-173.5 399,-179.5 393,-179.5\"/>\n<text text-anchor=\"middle\" x=\"344.5\" y=\"-164.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"344.5\" y=\"-149.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 43</text>\n<text text-anchor=\"middle\" x=\"344.5\" y=\"-134.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 43, 0]</text>\n<text text-anchor=\"middle\" x=\"344.5\" y=\"-119.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 雪莉</text>\n</g>\n<!-- 7&#45;&gt;8 -->\n<g id=\"edge8\" class=\"edge\">\n<title>7&#45;&gt;8</title>\n<path fill=\"none\" stroke=\"black\" d=\"M374.54,-222.91C370.25,-211.98 365.59,-200.14 361.25,-189.11\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"364.46,-187.69 357.54,-179.67 357.94,-190.25 364.46,-187.69\"/>\n</g>\n<!-- 9 -->\n<g id=\"node10\" class=\"node\">\n<title>9</title>\n<path fill=\"#ffffff\" stroke=\"black\" d=\"M540,-187C540,-187 435,-187 435,-187 429,-187 423,-181 423,-175 423,-175 423,-116 423,-116 423,-110 429,-104 435,-104 435,-104 540,-104 540,-104 546,-104 552,-110 552,-116 552,-116 552,-175 552,-175 552,-181 546,-187 540,-187\"/>\n<text text-anchor=\"middle\" x=\"487.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">脯氨酸 &lt;= 742.5</text>\n<text text-anchor=\"middle\" x=\"487.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.5</text>\n<text text-anchor=\"middle\" x=\"487.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 2</text>\n<text text-anchor=\"middle\" x=\"487.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [1, 1, 0]</text>\n<text text-anchor=\"middle\" x=\"487.5\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 琴酒</text>\n</g>\n<!-- 7&#45;&gt;9 -->\n<g id=\"edge9\" class=\"edge\">\n<title>7&#45;&gt;9</title>\n<path fill=\"none\" stroke=\"black\" d=\"M424.15,-222.91C431.68,-213.83 439.73,-204.12 447.48,-194.77\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"450.22,-196.95 453.91,-187.02 444.83,-192.49 450.22,-196.95\"/>\n</g>\n<!-- 10 -->\n<g id=\"node11\" class=\"node\">\n<title>10</title>\n<path fill=\"#e58139\" stroke=\"black\" d=\"M463,-68C463,-68 374,-68 374,-68 368,-68 362,-62 362,-56 362,-56 362,-12 362,-12 362,-6 368,0 374,0 374,0 463,0 463,0 469,0 475,-6 475,-12 475,-12 475,-56 475,-56 475,-62 469,-68 463,-68\"/>\n<text text-anchor=\"middle\" x=\"418.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"418.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 1</text>\n<text text-anchor=\"middle\" x=\"418.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [1, 0, 0]</text>\n<text text-anchor=\"middle\" x=\"418.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 琴酒</text>\n</g>\n<!-- 9&#45;&gt;10 -->\n<g id=\"edge10\" class=\"edge\">\n<title>9&#45;&gt;10</title>\n<path fill=\"none\" stroke=\"black\" d=\"M461.81,-103.73C456.29,-94.97 450.45,-85.7 444.91,-76.91\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"447.78,-74.89 439.48,-68.3 441.85,-78.63 447.78,-74.89\"/>\n</g>\n<!-- 11 -->\n<g id=\"node12\" class=\"node\">\n<title>11</title>\n<path fill=\"#39e581\" stroke=\"black\" d=\"M594,-68C594,-68 505,-68 505,-68 499,-68 493,-62 493,-56 493,-56 493,-12 493,-12 493,-6 499,0 505,0 505,0 594,0 594,0 600,0 606,-6 606,-12 606,-12 606,-56 606,-56 606,-62 600,-68 594,-68\"/>\n<text text-anchor=\"middle\" x=\"549.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"549.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 1</text>\n<text text-anchor=\"middle\" x=\"549.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 1, 0]</text>\n<text text-anchor=\"middle\" x=\"549.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 雪莉</text>\n</g>\n<!-- 9&#45;&gt;11 -->\n<g id=\"edge11\" class=\"edge\">\n<title>9&#45;&gt;11</title>\n<path fill=\"none\" stroke=\"black\" d=\"M510.59,-103.73C515.49,-95.06 520.68,-85.9 525.62,-77.18\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"528.76,-78.73 530.65,-68.3 522.67,-75.28 528.76,-78.73\"/>\n</g>\n<!-- 13 -->\n<g id=\"node14\" class=\"node\">\n<title>13</title>\n<path fill=\"#e0cef8\" stroke=\"black\" d=\"M751.5,-306C751.5,-306 629.5,-306 629.5,-306 623.5,-306 617.5,-300 617.5,-294 617.5,-294 617.5,-235 617.5,-235 617.5,-229 623.5,-223 629.5,-223 629.5,-223 751.5,-223 751.5,-223 757.5,-223 763.5,-229 763.5,-235 763.5,-235 763.5,-294 763.5,-294 763.5,-300 757.5,-306 751.5,-306\"/>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">颜色强度 &lt;= 5.355</text>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.49</text>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 7</text>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 3, 4]</text>\n<text text-anchor=\"middle\" x=\"690.5\" y=\"-230.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 贝尔摩德</text>\n</g>\n<!-- 12&#45;&gt;13 -->\n<g id=\"edge13\" class=\"edge\">\n<title>12&#45;&gt;13</title>\n<path fill=\"none\" stroke=\"black\" d=\"M690.5,-341.91C690.5,-333.65 690.5,-324.86 690.5,-316.3\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"694,-316.02 690.5,-306.02 687,-316.02 694,-316.02\"/>\n</g>\n<!-- 16 -->\n<g id=\"node17\" class=\"node\">\n<title>16</title>\n<path fill=\"#e6843d\" stroke=\"black\" d=\"M971.5,-306C971.5,-306 857.5,-306 857.5,-306 851.5,-306 845.5,-300 845.5,-294 845.5,-294 845.5,-235 845.5,-235 845.5,-229 851.5,-223 857.5,-223 857.5,-223 971.5,-223 971.5,-223 977.5,-223 983.5,-229 983.5,-235 983.5,-235 983.5,-294 983.5,-294 983.5,-300 977.5,-306 971.5,-306\"/>\n<text text-anchor=\"middle\" x=\"914.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">灰的碱性 &lt;= 27.5</text>\n<text text-anchor=\"middle\" x=\"914.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.039</text>\n<text text-anchor=\"middle\" x=\"914.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 50</text>\n<text text-anchor=\"middle\" x=\"914.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [49, 1, 0]</text>\n<text text-anchor=\"middle\" x=\"914.5\" y=\"-230.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 琴酒</text>\n</g>\n<!-- 12&#45;&gt;16 -->\n<g id=\"edge16\" class=\"edge\">\n<title>12&#45;&gt;16</title>\n<path fill=\"none\" stroke=\"black\" d=\"M751.12,-350.84C777.31,-337.16 808.28,-320.98 836.18,-306.41\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"837.88,-309.47 845.12,-301.74 834.64,-303.27 837.88,-309.47\"/>\n</g>\n<!-- 14 -->\n<g id=\"node15\" class=\"node\">\n<title>14</title>\n<path fill=\"#39e581\" stroke=\"black\" d=\"M671,-179.5C671,-179.5 582,-179.5 582,-179.5 576,-179.5 570,-173.5 570,-167.5 570,-167.5 570,-123.5 570,-123.5 570,-117.5 576,-111.5 582,-111.5 582,-111.5 671,-111.5 671,-111.5 677,-111.5 683,-117.5 683,-123.5 683,-123.5 683,-167.5 683,-167.5 683,-173.5 677,-179.5 671,-179.5\"/>\n<text text-anchor=\"middle\" x=\"626.5\" y=\"-164.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"626.5\" y=\"-149.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 3</text>\n<text text-anchor=\"middle\" x=\"626.5\" y=\"-134.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 3, 0]</text>\n<text text-anchor=\"middle\" x=\"626.5\" y=\"-119.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 雪莉</text>\n</g>\n<!-- 13&#45;&gt;14 -->\n<g id=\"edge14\" class=\"edge\">\n<title>13&#45;&gt;14</title>\n<path fill=\"none\" stroke=\"black\" d=\"M668.3,-222.91C662.26,-211.87 655.71,-199.9 649.62,-188.77\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"652.51,-186.76 644.64,-179.67 646.37,-190.12 652.51,-186.76\"/>\n</g>\n<!-- 15 -->\n<g id=\"node16\" class=\"node\">\n<title>15</title>\n<path fill=\"#8139e5\" stroke=\"black\" d=\"M823.5,-179.5C823.5,-179.5 713.5,-179.5 713.5,-179.5 707.5,-179.5 701.5,-173.5 701.5,-167.5 701.5,-167.5 701.5,-123.5 701.5,-123.5 701.5,-117.5 707.5,-111.5 713.5,-111.5 713.5,-111.5 823.5,-111.5 823.5,-111.5 829.5,-111.5 835.5,-117.5 835.5,-123.5 835.5,-123.5 835.5,-167.5 835.5,-167.5 835.5,-173.5 829.5,-179.5 823.5,-179.5\"/>\n<text text-anchor=\"middle\" x=\"768.5\" y=\"-164.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"768.5\" y=\"-149.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 4</text>\n<text text-anchor=\"middle\" x=\"768.5\" y=\"-134.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 0, 4]</text>\n<text text-anchor=\"middle\" x=\"768.5\" y=\"-119.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 贝尔摩德</text>\n</g>\n<!-- 13&#45;&gt;15 -->\n<g id=\"edge15\" class=\"edge\">\n<title>13&#45;&gt;15</title>\n<path fill=\"none\" stroke=\"black\" d=\"M717.56,-222.91C725.07,-211.65 733.22,-199.42 740.76,-188.11\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"743.75,-189.93 746.39,-179.67 737.93,-186.05 743.75,-189.93\"/>\n</g>\n<!-- 17 -->\n<g id=\"node18\" class=\"node\">\n<title>17</title>\n<path fill=\"#e58139\" stroke=\"black\" d=\"M963,-179.5C963,-179.5 866,-179.5 866,-179.5 860,-179.5 854,-173.5 854,-167.5 854,-167.5 854,-123.5 854,-123.5 854,-117.5 860,-111.5 866,-111.5 866,-111.5 963,-111.5 963,-111.5 969,-111.5 975,-117.5 975,-123.5 975,-123.5 975,-167.5 975,-167.5 975,-173.5 969,-179.5 963,-179.5\"/>\n<text text-anchor=\"middle\" x=\"914.5\" y=\"-164.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"914.5\" y=\"-149.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 49</text>\n<text text-anchor=\"middle\" x=\"914.5\" y=\"-134.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [49, 0, 0]</text>\n<text text-anchor=\"middle\" x=\"914.5\" y=\"-119.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 琴酒</text>\n</g>\n<!-- 16&#45;&gt;17 -->\n<g id=\"edge17\" class=\"edge\">\n<title>16&#45;&gt;17</title>\n<path fill=\"none\" stroke=\"black\" d=\"M914.5,-222.91C914.5,-212.2 914.5,-200.62 914.5,-189.78\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"918,-189.67 914.5,-179.67 911,-189.67 918,-189.67\"/>\n</g>\n<!-- 18 -->\n<g id=\"node19\" class=\"node\">\n<title>18</title>\n<path fill=\"#39e581\" stroke=\"black\" d=\"M1094,-179.5C1094,-179.5 1005,-179.5 1005,-179.5 999,-179.5 993,-173.5 993,-167.5 993,-167.5 993,-123.5 993,-123.5 993,-117.5 999,-111.5 1005,-111.5 1005,-111.5 1094,-111.5 1094,-111.5 1100,-111.5 1106,-117.5 1106,-123.5 1106,-123.5 1106,-167.5 1106,-167.5 1106,-173.5 1100,-179.5 1094,-179.5\"/>\n<text text-anchor=\"middle\" x=\"1049.5\" y=\"-164.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">gini = 0.0</text>\n<text text-anchor=\"middle\" x=\"1049.5\" y=\"-149.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 1</text>\n<text text-anchor=\"middle\" x=\"1049.5\" y=\"-134.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value = [0, 1, 0]</text>\n<text text-anchor=\"middle\" x=\"1049.5\" y=\"-119.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">class = 雪莉</text>\n</g>\n<!-- 16&#45;&gt;18 -->\n<g id=\"edge18\" class=\"edge\">\n<title>16&#45;&gt;18</title>\n<path fill=\"none\" stroke=\"black\" d=\"M961.34,-222.91C974.96,-211.1 989.83,-198.22 1003.4,-186.45\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"1005.97,-188.86 1011.23,-179.67 1001.38,-183.57 1005.97,-188.86\"/>\n</g>\n</g>\n</svg>\n",
      "text/plain": [
       "<graphviz.sources.Source at 0x1efca247c10>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "import graphviz   # 既需要在python环境中安装graphviz包（pip或conda），还需要在电脑上安装graphviz并配置系统的path环境变量。\n",
    "from sklearn import tree\n",
    "\n",
    "# feature_name = wine_raw.feature_names\n",
    "feature_name = ['酒精','苹果酸','灰','灰的碱性','镁','总酚','类黄酮','非黄烷类酚类','花青素','颜色强度','色调','od280/od315稀释葡萄酒','脯氨酸']\n",
    "dot_data = tree.export_graphviz(my_clf_tree\n",
    "                               ,feature_names = feature_name\n",
    "                               ,class_names = [\"琴酒\",\"雪莉\",\"贝尔摩德\"]\n",
    "                               ,filled = True    # 是否填充颜色\n",
    "                               ,rounded = True)  # 框的形状\n",
    "graph = graphviz.Source(dot_data)\n",
    "graph"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.13 ('ai_txtbook')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "3f7851e38dce13968630152acfada13e17192bdc676945d7b675298112638bc3"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
